package com.swf.seed.security.cert;
import java.io.InputStream;
import java.io.OutputStream;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

@SuppressWarnings("restriction")
public class SecurityBase64Signer {
	private static final BASE64Decoder decoder =   new BASE64Decoder();
	private static final BASE64Encoder encoder =   new BASE64Encoder();
	/**
	 * BASE64解密
	 * 
	 * @param key
	 * @return
	 * @throws Exception
	 */
	public static byte[] decryptBASE64(String key) throws Exception {
		return decoder.decodeBuffer(key);
	}
	public static String decryptBASE64(String key,String charset) throws Exception {
		return new String(decoder.decodeBuffer(key),charset);
	}
	public static byte[] decryptBASE64(InputStream is) throws Exception {
		return decoder.decodeBuffer(is);
	}
	public static void decryptBASE64(InputStream is,OutputStream os) throws Exception {
		decoder.decodeBuffer(is,os);
	}

	/**
	 * BASE64加密
	 * 
	 * @param key
	 * @return
	 * @throws Exception
	 */
	public static String encryptBASE64(byte[] key) throws Exception {
		return encoder.encodeBuffer(key);
	}
	public static void encryptBASE64(byte[] key,OutputStream os) throws Exception {
		encoder.encodeBuffer(key,os);
	}
	public static void encryptBASE64(InputStream is,OutputStream os) throws Exception {
		encoder.encode(is, os);
	}
}
